package com.sifang.sfuserservice.handler;

import com.sifang.sfuserservice.response.ResponseEnum;
import com.sifang.sfuserservice.response.ServerResponseEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.TransactionException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 自定义错误处理器，除了授权只要请求服务器成功，就返回200，错误根据错误码前端进行处理
 *
 */
@RestController
@RestControllerAdvice
public class DefaultExceptionHandlerConfig {

	private static final Logger logger = LoggerFactory.getLogger(DefaultExceptionHandlerConfig.class);

	@ExceptionHandler(Exception.class)
	public ResponseEntity<ServerResponseEntity<Object>> exceptionHandler(Exception e) throws TransactionException {
		return ResponseEntity.status(HttpStatus.OK).body(ServerResponseEntity.fail(ResponseEnum.USER_REGISTER_EXCEPTION));
	}
}
